from flask import Flask, request, render_template, escape
import requests
import matplotlib.pyplot as plt
import json
from weatherapi import tianqi


app = Flask(__name__)

@app.route("/", methods = ["GET"])
def hello() -> str:
	return "欢迎使用Ally天气预报!"

@app.route("/chaxun", methods = ["GET"])
def chaxun():
    return render_template("entry.html")


@app.route("/jieguo", methods = ["GET"])
def jieguo():
    key='7bdac67270c803349259a1845da5cdf6'
    city='440100'
    extensions='base'
    a = tianqi(key,city,extensions)
    b = a['lives'][0]['city']
    c = a['lives'][0]['weather']
    d = a['lives'][0]['temperature']
    e = a['lives'][0]['windpower']
    f = a['lives'][0]['humidity']
    return render_template('111.html',city=str(b),weather=str(c),temperature=str(d),windpower=str(e),humidity=str(f))


@app.route("/bianse",methods=["POST"])
def bianse():
	col = request.form["col"]
	print(col)

	return render_template('entry.html',color = col)

@app.route("/viewlog")
def viewlog():
  contents=[]
  with open("vsearch.log","r") as log:
    for line in log:
      contents.append([])
      for item in line.split("|"):
        contents[-1].append(escape(item))
    titles= ["Formdata","Host_url","Remote_addr"]
  return render_template('entry.html',the_data=contents,the_titles=titles)

if __name__ == '__main__':
    app.run(debug=True)